package cn.wolfcode.wechat.service.impl;

import cn.wolfcode.wechat.domain.LocationBlacklist;
import cn.wolfcode.wechat.mapper.LocationBlacklistMapper;
import cn.wolfcode.wechat.query.LocationBlacklistQueryObject;
import cn.wolfcode.wechat.service.ILocationBlacklistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LocationBlacklistServiceImpl implements ILocationBlacklistService {

    @Autowired
    private LocationBlacklistMapper locationBlacklistMapper;

    @Override
    public int insert(LocationBlacklist locationBlacklist) {
        return locationBlacklistMapper.insert(locationBlacklist);
    }


    @Override
    public int update(LocationBlacklist locationBlacklist) {
        return locationBlacklistMapper.update(locationBlacklist);
    }

    @Override
    public void saveOrUpdate(LocationBlacklist locationBlacklist) {
        if (locationBlacklist.getId() == null) {
            this.insert(locationBlacklist);
        } else {
            this.update(locationBlacklist);
        }
    }

    @Override
    public int delete(Long id) {
        return locationBlacklistMapper.deleteById(id);
    }

    @Override
    public LocationBlacklist get(Long id) {
        return locationBlacklistMapper.findById(id);
    }

    @Override
    public List<LocationBlacklist> getAll(LocationBlacklistQueryObject qo) {
        return locationBlacklistMapper.find(qo);
    }

    @Override
    public boolean findByKeyword(String keyword) {
        LocationBlacklistQueryObject qo = new LocationBlacklistQueryObject();
        List<LocationBlacklist> all = this.getAll(qo);
        for (LocationBlacklist locationBlacklist : all) {
            if (keyword.contains(locationBlacklist.getKeyword())) {
                return false;
            }
        }
        return true;
    }
}
